Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfjs-dist

Package Overview
Dependencies
Maintainers
3
Versions
1543
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfjs-dist

Generic build of Mozilla's PDF.js library.

  • 3.11.174
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8M
decreased by-1.87%
Maintainers
3
Weekly downloads
 
Created

What is pdfjs-dist?

The pdfjs-dist package is a pre-built version of the PDF.js library, which is a general-purpose, web standards-based platform for parsing and rendering PDFs. It allows you to display PDF files in your web pages without the need for a native PDF reader. The package provides a wide range of features including, but not limited to, rendering PDFs, reading PDF metadata, and interacting with PDF content programmatically.

What are pdfjs-dist's main functionalities?

Rendering PDF pages to a canvas element

This code sample demonstrates how to render the first page of a PDF to a canvas element in the browser. It uses the getDocument method to load the PDF and the getPage method to access a specific page, then renders it to the provided canvas context.

const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js');

async function renderPage(url, canvasContext) {
  const pdf = await pdfjsLib.getDocument(url).promise;
  const page = await pdf.getPage(1);
  const viewport = page.getViewport({ scale: 1.5 });
  const renderContext = {
    canvasContext: canvasContext,
    viewport: viewport
  };
  await page.render(renderContext).promise;
}

Extracting text from a PDF page

This code sample shows how to extract text content from the first page of a PDF. It retrieves the text items from the page and then maps them to strings, joining them to form the full text content of the page.

const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js');

async function extractTextFromPage(url) {
  const pdf = await pdfjsLib.getDocument(url).promise;
  const page = await pdf.getPage(1);
  const textContent = await page.getTextContent();
  return textContent.items.map(item => item.str).join(' ');
}

Other packages similar to pdfjs-dist

Keywords

FAQs

Package last updated on 24 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc